<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<@head/>
<script type="text/javascript" src="${path}/js/dojo/dojo/layout.gzjs"></script>
<script type="text/javascript">
//	dojo.require("dijit.dijit");
//	dojo.require("dijit.layout.AccordionContainer");
//	dojo.require("dijit.layout.TabContainer");
//	dojo.require("dijit.Toolbar");
//	dojo.require("dijit.layout.BorderContainer");
//	dojo.require("dijit.layout.ContentPane");
//	dojo.require("dijit.form.Button");
//	dojo.require("dojox.layout.ExpandoPane");
//	dojo.require("dojo.data.ItemFileReadStore");
//	dojo.require("dijit.Tree");
//	dojo.require("dijit.tree.ForestStoreModel");
//	dojo.require("dijit.Dialog");
</script>
<link rel="stylesheet"
	  href="${path}/js/dojo/dojox/layout/resources/ExpandoPane.css">
<body class="${theme}">
<div dojoType="dijit.layout.BorderContainer"
	 style="width: 100%; height: 100%;" id="layoutContainer">
	<div dojoType="dijit.layout.ContentPane" region="top"
		 style="height: 50px; padding: 0">
		<div style="height: 29px; width: 100%; over-flow: hidden;">
			log标志位置
		</div>
		<div id="toolbar1" dojoType="dijit.Toolbar"
			 style="height: 20px; width: 100%" dir="rtl">
			<div id="btnQuit" dojoType="dijit.form.Button"
				 onClick="quitSystem">
				退出系统
			</div>
			<div id="btnChangepwd" dojoType="dijit.form.Button"
				 onClick="changePassword">
				修改密码
			</div>
			<div id="btnLock" dojoType="dijit.form.Button"
				 onClick="lockSystem">
				锁定系统
			</div>
		<#--<div id="btnOutput" dojoType="dijit.form.Button"-->
		<#--onClick="btnChangepwd_Click">-->
		<#--出库管理-->
		<#--</div>-->
		</div>
	</div>
	<div id="leftNav" dojoType="dojox.layout.ExpandoPane" title="操作菜单"
		 style="width: 150px; over-flow: hidden;" region="left"
		 splitter="true">
		<div dojoType="dijit.layout.AccordionContainer" id="accordion"
			 style="width: 150px; over-flow: hidden;">
		<#list menus as first>
			<div dojoType="dijit.tree.ForestStoreModel"
				 childrenAttrs="subMenus" store="${first.id}_Store"
				 jsId="${first.id}_Model">
			</div>
			<div dojoType="dijit.layout.ContentPane" title="${(first.name)!}"
				 iconClass="${first.icon!}" id="${first.id}">
				<div dojoType="dijit.Tree" id="${first.id}_Tree"
					 openOnClick="true" showRoot="false" model="${first.id}_Model">
					<script type="dojo/method" event="getIconClass"
							args="item,opened">
						if(item && this.model.store.isItem(item)){
						return this.model.store.getValue(item,'icon');
						}
						return null;
					</script>
				<#--<script type="dojo/method" event="getTooltip" args="item,opened">-->
				<#--return item && ("Tooltip for " + this.model.getLabel(item));-->
				<#--</script>-->
					<script type="dojo/method" event="onClick" args="item">
						refreshTabContainer(this.model.store,item);
					</script>
				</div>
			</div>
		</#list>
		</div>
	</div>
	<div jsId="mainTabContainer" id="mainTabContainer" region="center"
		 dojoType="dijit.layout.TabContainer" style="width: 100%;">
	</div>
	<!--<div id="onlineUser" dojoType="dojox.layout.ExpandoPane"
				 region="right" title="在线用户" startExpanded="false"
				 style="width: 150px;">
				 <div dojoType="dijit.layout.AccordionContainer">
					 <div dojoType="dijit.layout.ContentPane" title="我的好友"
						 id="myFriends">
						 <ul>
							 <li>
								 <span>王聪</span>
							 </li>
							 <li>
								 <span>刘黑棋</span>
							 </li>
							 <li>
								 <span>何太急</span>
							 </li>
							 <li>
								 <span>刘文祥</span>
							 </li>
							 <li>
								 <span>罗志聪</span>
							 </li>
							 <li>
								 <span>李然</span>
							 </li>
						 </ul>
					 </div>
					 <div dojoType="dijit.layout.ContentPane" title="联系人" id="linkman">
						 <span>王总</span>
						 <span>李总</span>
						 <span>苏总</span>
					 </div>
					 <div dojoType="dijit.layout.ContentPane" title="临时联系人"
						 id="tempLinkman">
						 <span>小王</span>
						 <span>小李</span>
						 <span>小苏</span>
					 </div>
				 </div>
			 </div>-->
	<div id="copyrightInfo" dojoType="dijit.Toolbar" region="bottom"
		 style="height: 20px; text-align: center;">
		<a href="target">xxxx公司</a>
	</div>
</div>

<div dojoType="dijit.Dialog" jsId="dialog" id="dialog" loadingMessage="数据加载中，请稍后...">
	<script type="dojo/method" event="onHide">
		this.set("content","");
	</script>
</div>
<div dojoType="dijit.Dialog" id="confirm" jsId="confirm" duration="1" showTitle="true"
	 style="width: 200px; height: auto">
	<div id="confirmContent" class="dijitDialogPaneContentArea" style="text-align:center">
	</div>
	<div class="dijitDialogPaneActionBar">
		<button dojoType="dijit.form.Button" type="button"
				onClick="confirm.onExecute();">
			确认
		</button>
		<button dojoType="dijit.form.Button" type="button"
				onClick="confirm.onCancel();">
			取消
		</button>
	</div>
</div>
<div dojoType="dijit.Dialog" id="_alert" jsId="_alert" showTitle="true" modal="true"
	 style="width: 200px; height: auto">
	<div id="alertContent" class="dijitDialogPaneContentArea" style="text-align:center">
	</div>
	<div class="dijitDialogPaneActionBar">
		<button dojoType="dijit.form.Button" type="button"
				onClick="_alert.onExecute();">
			确认
		</button>
	</div>
</div>
</body>
</html>
<script type="text/javascript">
/*****************************菜单数据--开始**********************/
<#list menus as first>
var ${first.id}_Store = new dojo.data.ItemFileReadStore({
	data:{
		identifier:"id",
		label:"name",
		items:${first.menuJson!"[]"}
	}
})
</#list>
/*****************************菜单数据--结束**********************/
/**
 * 刷新标签页
 * @param store 菜单数据源
 * @param menu  菜单
 */
function refreshTabContainer(store, menu) {
	//dojo.byId('decorator').style.display="block";
	var id = "tab_" + store.getValue(menu, 'id');
	var title = store.getValue(menu, 'name');
	var url = "${path}/" + store.getValue(menu, 'url');
	var icon = store.getValue(menu, 'icon');
	openTab({id:id,title:title,url:url,icon:icon});
}

/**
 * 打开一个新的标签页
 * @param arg 标签页参数
 */
function openTab(arg) {
	var id = arg.id;
	var title = arg.title;
	var url = arg.url;
	var icon = arg.icon || "";
	//判断是否已经打开过此菜单
	var idx = mainTabContainer.getChildren().length;
	for (var i = 0; i < mainTabContainer.getChildren().length; i++) {
		var child = mainTabContainer.getChildren()[i];
		if (child.get('id') == id) {
			mainTabContainer.selectChild(child, true);
			dojo.query('iframe', child.attr('domNode')).attr('src', url);
			return;
		}
	}
	//如果没打开过，就添加一个新的页签
	//添加新的页签之前先判断一下是否超过了最大的页签数限制
	if (mainTabContainer.getChildren().length > 20) {
		Warn("超过了最大页签数的限制，请先关闭其他页签");
		return;
	}
	var cp = new dijit.layout.ContentPane({"id":id ,"title":"<b>" + title + "</b>", closable: true,refreshOnShow:false});
	cp.domNode.innerHTML = "<iframe frameborder='0' style='width:100%; height:99.5%' src='" + url + "'></iframe>";
	mainTabContainer.addChild(cp);
	mainTabContainer.selectChild(cp, true);
}

/**
 * 关闭指定tab
 * @param tabId
 */
function closeTab(tabId) {

}

/**
 * 关闭当前tab页面
 */
function closeCurrentTab() {
	var current = mainTabContainer.selectedChildWidget;
	if (current) {
		mainTabContainer.closeChild(current);
	}
}

var command = {};
/**
 * 发布一个事件
 */
function publish(topic, args) {
	dojo.publish(topic, args);
}
/**
 * 订阅一个事件
 * @param pageId 要注册页面的Id
 * @param topic 要订阅事件的主题
 * @param context 事件执行的上下文
 * @param func 注册的函数
 */
function subscribe(pageId, topic, context, func) {
	if (!command[pageId]) {
		command[pageId] = [];
	}
	command[pageId].push(dojo.subscribe(topic, context, func));
}
/**
 * 弹出一个警告信息
 * @param content  警告内容
 * @param okCall   确定按钮压下的事件
 * @param context  事件执行的上下文
 */
function Warn(content, okCall, context) {
	var okCall = okCall || null;
	var context = context || null;
	_Alert('警告', 'warn', content, okCall, context);
}
/**
 * 弹出一个提示信息
 * @param content 提示内容
 * @param okCall  确定按钮压下的事件
 * @param context 事件执行的上下文
 */
function Info(content, okCall, context) {
	var okCall = okCall || null;
	var vacontext = context || null;
	_Alert('信息', 'info', content, okCall, context);
}
/**
 * 弹出一个错误信息
 * @param content  错误内容
 * @param okCall   确定按钮压下的事件
 * @param context  事件执行的上下文
 */
function Error(content, okCall, context) {
	var okCall = okCall || null;
	var context = context || null;
	_Alert('错误', 'error', content, okCall, context);
}
/**
 * 弹出框的私有方法
 * @param title 弹出框的标题
 * @param iconClass 弹出框的图标
 * @param content 弹出框的内容
 * @param okCall 确认时的处理函数
 * @param context 处理函数的上下文
 */
function _Alert(title, iconClass, message, okCall, context) {
	_alert.set('title', title);
	_alert.set('iconClass', iconClass);
	var node = dojo.query("#alertContent", _alert.domNode);
	node.empty();
	node.addContent(message);
	delete _alert.onExecute;
	_alert.onExecute = function() {
		_alert.hide();
		if (dojo.isFunction(okCall) || dojo.isString(okCall))
			okCall.apply(context);
	}
	_alert.show();
}

/**
 * 带有确认和取消按钮的函数
 * @param arg
 */
function Confirm(arg) {
	var title = arg.title || "消息";
	var msg = arg.msg || "";
	var context = arg.context || null;
	var okCall = arg.okCall || {};
	var cancelCall = arg.cancelCall;
	confirm.set("title", title);
	var node = dojo.query("#confirmContent", confirm.domNode);
	node.empty();
	node.addContent(msg);
	delete confirm.onExecute;
	delete confirm.onCancel;
	confirm.onExecute = function() {
		confirm.hide();
		if (dojo.isFunction(okCall) || dojo.isString(okCall))
			okCall.apply(context);
	};
	confirm.onCancel = function() {
		confirm.hide();
		if (dojo.isFunction(cancelCall) || dojo.isString(cancelCall))
			cancelCall.apply(context);
	};
	confirm.show();
}

/**
 * 取消页面的事件绑定
 */
function clearEvents(pageId) {
	if (command[pageId]) {
		dojo.forEach(command[pageId], function(handle) {
			dojo.unsubscribe(handle);
		})
		delete command[pageId];
	}
}

/**
 * 打开一个对话框
 * @param window 打开窗口的窗体对象
 * @param url 打开窗体的url
 * @param ioArgs 打开窗体的参数
 * @param title 打开窗体的标题
 * @param width 打开窗体的高度
 * @param height 打开窗体的高度
 */
function openDialog(arg) {
	var url = arg.url;
	//增加一个随机数，防止请求不被提交
    if (url.indexOf('?') == -1) {
        url = url + "?randomDateStr=" + new Date();
    } else {
        url = url + "&randomDateStr=" + new Date();
    }
	var wd = arg.width || 800;
	var ht = arg.height || 600;
	var tt = arg.title || '';
	dialog.set('title', tt);
	dialog.set('style', {width:wd + "px",height:ht + "px"});
	var iframe = "<iframe frameborder='0' style='width: " + wd + "px; height: " + ht + "px;' src='" + url + "'></iframe>";
	dialog.set("content", iframe);
	dialog.show();
}

/**
 * 关闭dialog
 */
function closeDialog() {
	dialog.hide();
}

/**
 * 锁定系统按钮压下的对应事件
 */
function lockSystem() {
	var background = document.getElementById("background");
	//background.style.z-index = 10000;
}

/**
 * 解锁按钮压下的对应事件
 */
function unLockSystem() {

}

/**
 * 修改按钮按钮压下事件
 */
function changePassword() {
	alert("修改密码");
}

/**
 * 退出系统按钮压下处理事件
 */
function quitSystem() {
	location.href = "${path}/index.jsp";
}
</script>
